home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / libg_261.zip / libg_261 / libg++ / src / init_main.c < prev    next >
C/C++ Source or Header  |  1991-08-14  |  2KB  |  57 lines

  1. /*  init_main.c:     Static Constructor Initialization for Dynamically
  2.  *                    Linked Libraries
  3.  *  Author:           James Kempf
  4.  *  Created On:       Fri Dec 21 08:31:07 1990
  5.  *  Last Modified By: James Kempf
  6.  *  Last Modified On: Wed Apr 24 10:41:25 1991
  7.  *  Update Count:     46
  8. */
  9.  
  10.  
  11. #include "dldefs.h"
  12.  
  13. /* This global is used to communicate the ctor/dtor list address to 
  14.  * dynamically linked libraries. Some static linkers may have trouble
  15.  * with initialized data in PIC code. gcc can generate initialization
  16.  * functions for any user data, but the ctor/dtor lists are generated
  17.  * by the linker. So we use this ruse to make sure the address gets
  18.  * to the initialization function. This code should *always* run single
  19.  * threaded.
  20. */
  21. int * __function_list_addr = 0;
  22.  
  23. extern int __CTOR_LIST__;
  24. extern int __DTOR_LIST__;
  25.  
  26. int __main();
  27. void INIT_FUN();
  28. void FINI_FUN();
  29. void _initialize_dynamic_libs();
  30. void _finalize_dynamic_libs();
  31. void exit(/*int*/);
  32. void _exit(/*int*/);
  33. void _cleanup();
  34.  
  35. /*************************************************************************
  36.  * Main initialization and finalization
  37.  ************************************************************************/
  38.  
  39. /* __main-Initialize dynamically linked libraries, then main. */
  40.  
  41. int __main()
  42. {
  43.     _initialize_dynamic_libs();
  44.     __function_list_addr = &__CTOR_LIST__;
  45.     INIT_FUN();
  46.     return(0);
  47. }
  48.  
  49. void exit( int status)
  50. {
  51.     __function_list_addr = &__DTOR_LIST__;
  52.     FINI_FUN(); 
  53.     _finalize_dynamic_libs();
  54.     _cleanup();
  55.     _exit(status);
  56. }
  57.